package com.clazzwork.movie;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author nmm
 * @date 2024-03-2024/3/21
 * @deriction njm......
 */
public class MovieRunnable implements  Runnable{

    private int totalticket=100;

    Lock lock=new ReentrantLock();

    @Override
    public void run() {
        while (true){
            try {
                lock.lock();
               if (totalticket>0){
                    System.out.println(Thread.currentThread().getName() + "出售了第 " + totalticket-- + " 张票");
                }else {
                   break;
               }
            }finally {
                lock.unlock();
            }
        }
    }
}
